// Copyright Leonid Shlyapnikov 2010
// Distributed under the GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.html
//    author: Leonid Shlyapnikov, created on: Mar 16, 2010

#include "./knr2.h"

#include <cstring>
#include <cstdlib>
#include <climits>

namespace fixparser {

void itoa(int n, char s[]) {
    int i, sign;
    sign = n;

    i = 0;
    do {
        s[i++] = static_cast<char>(abs(n % 10) + '0');
    } while ( n /= 10 );
    if (sign < 0)
        s[i++] = '-';

    s[i] = '\0';
    reverse(s);
}

void reverse(char s[]) {
    int c, i, j;
    for ( i = 0, j = static_cast<int>(strlen(s)-1); i < j; i++, j--) {
        c = s[i];
        s[i] = s[j];
        s[j] = static_cast<char>(c);
    }
}

}
